﻿using System;
using System.Collections.Generic;

namespace 解释器模式_Message
{
   public abstract class AbstractExpression
    {
       public void Interpret(Context context)
       {
           if (string.IsNullOrEmpty(context.Input))
           {
               return;
           }
            context.Output += GetCSharp(context.Input);
        }
        /// <summary>
        /// 获得输入内容所对应的C#代码
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        private string GetCSharp(string source)
       {
            var csharp = "";
            var word = "";
            // 从输入内容中取得要解释的词
            word = GetWord(source);
            // 从字典中找到word所对应的C#代码
            GetDictionary().TryGetValue(word, out csharp);
            return csharp;
        }

        /// <summary>
        /// 从输入内容中取得要解释的词
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public abstract string GetWord(string source);
        /// <summary>
        /// 获取字典
        /// </summary>
        /// <returns></returns>
        public abstract Dictionary<string, string> GetDictionary();

    }
}
